package com.ljkj.cordial.chat.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ljkj.cordial.chat.R;
import com.ljkj.cordial.chat.widget.RectButtonHintDialog;

/**
 * @description:
 * @author: Panwei
 * @date: 2020/3/10 11:15
 */
public class UpdateDialog extends RectButtonHintDialog {

    CardView cardView;
    ProgressBar progressUpdate;
    TextView tvUpdateVersion;

    public UpdateDialog(@NonNull Context context) {
        super(context);
        setCancelable(false);
        setCanceledOnTouchOutside(false);

        cardView = findViewById(R.id.update_panel);
        progressUpdate = findViewById(R.id.progress_update);
        tvUpdateVersion = findViewById(R.id.tv_update_version);
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(R.layout.dialog_update);
    }

    public void setProgress(int progress) {
        progressUpdate.setProgress(progress);
    }

    public void setProgressText(CharSequence text) {
        tvUpdateVersion.setText(text);
    }

    public void setProgressComplateClick(View.OnClickListener listener) {
        tvUpdateVersion.setOnClickListener(listener);
    }

    public void setProgressError(CharSequence text) {
        progressUpdate.setProgress(100);
        tvUpdateVersion.setText(text);
        tvUpdateVersion.postDelayed(() -> cardView.setVisibility(View.GONE), 1500);
    }

    @Override
    public RectButtonHintDialog setSubmit(String content, View.OnClickListener listener) {
        return super.setSubmit(content, v -> {
            cardView.setVisibility(View.VISIBLE);
            listener.onClick(v);
        }, false);
    }

    @Override
    public RectButtonHintDialog setRightSubmit(String content, View.OnClickListener listener) {
        return super.setRightSubmit(content, v -> {
            setCancelable(true);
            cardView.setVisibility(View.VISIBLE);
            listener.onClick(v);
        }, false);
    }
}
